package com.wondersgroup.insurance.dnuilearn.views.svg_map;

import android.graphics.Color;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import java.util.LinkedList;

/**
 * Created by Administrator on 2017/6/1.
 */

public class ProvinceSVGHandler extends DefaultHandler {

    public LinkedList<ItemPath> list;
    ItemPath item;
    String elementName;
    int[] colorArr = new int[]{Color.BLUE,Color.CYAN,Color.GREEN,Color.MAGENTA,Color.YELLOW,Color.RED,Color.DKGRAY};

    @Override
    public void startDocument() throws SAXException {
        super.startDocument();
        list = new LinkedList<>();
    }

    @Override
    public void endDocument() throws SAXException {
        super.endDocument();
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
        super.startElement(uri, localName, qName, attributes);
        elementName = localName;
        if (elementName.equals("path")){
            item = new ItemPath();
            String pathStr = attributes.getValue("android:pathData");
            item.path = PathParser.createPathFromPathData(pathStr);
        }
    }

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
        super.endElement(uri, localName, qName);

        if (localName.equals("path")){

            list.add(item);
            item.color =colorArr [ list.size()%colorArr.length];
        }
    }

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
        super.characters(ch, start, length);
    }
}
